import { useEffect, useRef } from 'react';
/**
 *  @description 使用上与 useEffect 完全相同，仅仅是忽略了首次渲染，只在依赖项更新时执行。
 * 
 **/
const useUpdateEffect = (effect, deps) => {
  const isMounted = useRef(false);

  useEffect(() => {
    return () => {
      isMounted.current = false;
    };
  }, []);

  useEffect(() => {
    if (!isMounted.current) {
      isMounted.current = true;
    } else {
      return effect();
    }
  }, deps);
};

export default useUpdateEffect;
